package com.godGuang.servser.impl;

import com.godGuang.domain.Video;
import com.godGuang.domain.request.VideoRequest;
import com.godGuang.mapper.HealthVideoMapper;
import com.godGuang.servser.HealthVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author : 段敏强
 * @className : HealthVideoServiceImpl
 * @description : 描述说明该类的功能
 * @createTime : 2024/01/16 09:16
 */

/**
 * 健康视频业务实现类
 */


@Service
public class HealthVideoServiceImpl implements HealthVideoService {
    @Autowired
    private HealthVideoMapper healthVideoMapper;

    @Autowired
    private ContentServiceImpl contentService;

    /**
     * 添加健康视频
     *
     * @param video 视频对象
     */
    @Override
    public void healthVideoAdd(Video video) {
        // 1.将视频标题和简介中的特殊字符替换为“*”
        char[] charArray = video.getVideoCaption().toCharArray();
        // 2.将视频标题和简介中的特殊字符替换为“*”
        String videoCaption = "";
        for (char c : charArray) {
            // 2.将视频标题和简介中的特殊字符替换为“*”
            videoCaption += contentService.desensitizeText(String.valueOf(c));
        }

        // 2.将视频标题和简介中的特殊字符替换为“*”
        char[] charArray1 = video.getVideoName().toCharArray();
        // 2.将视频标题和简介中的特殊字符替换为“*”
        String videoName = "";
        // 2.将视频标题和简介中的特殊字符替换为“*”
        for (char c : charArray1) {
            videoName += contentService.desensitizeText(String.valueOf(c));
        }

        video.setVideoName(videoName);
        video.setVideoCaption(videoCaption);
        video.setVideoDelete(0);
        video.setVideoDate(new Date());
        healthVideoMapper.insert(video);
    }

    @Override
    public List<Video> healthVideoList(String videoName) {
        return healthVideoMapper.healthVideoList(videoName);
    }

    @Override
    public List<Video> healthVideoById(VideoRequest videoRequest) {
        if (videoRequest.getVideoId() == null){
            return healthVideoMapper.healthVideoListById(videoRequest.getUserId());
        }
        if (videoRequest.getUserId() == null){
            return healthVideoMapper.healthVideoById(videoRequest.getVideoId());
        }
        return null;
    }

    @Override
    public void healthVideoDelete(String videoId) {
        Integer videoDelete = 1;
        healthVideoMapper.healthVideoDelete(videoDelete,videoId);
    }

    @Override
    public void preferenceAdd(VideoRequest videoRequest) {
        healthVideoMapper.preferenceAdd(videoRequest);
    }

    @Override
    public List<Video> preferenceList(String userId) {
        return healthVideoMapper.healthVideoByIds(userId);
    }

    @Override
    public void preferenceDelete(VideoRequest videoRequest) {
        healthVideoMapper.preferenceDelete(videoRequest);
    }

    @Override
    public List<Video> preferenceById(VideoRequest videoRequest) {
        return healthVideoMapper.preferenceById(videoRequest);
    }


}
